package org.arch_learn.dubbo_demo.service_consumer_xml;

import org.apache.dubbo.rpc.RpcContext;
import org.arch_learn.dubbo_demo.api.HelloService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class XmlDubboConsumerMain {
    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:dubbo-consumer.xml");
        applicationContext.start();

        HelloService helloService = applicationContext.getBean(HelloService.class);
        System.in.read();
        while (true) {
            System.in.read();
            String hello = helloService.sayHello("world");
            Future<Object> future = RpcContext.getContext().getFuture();
            System.out.println("result:" + hello);
            System.out.println("future result:" + future.get());
        }
    }
}
